package com.lagou.ModelTest3.First.Three;

import java.util.Objects;

public class Student {
    //私有属性 姓名name 和 年龄age
    private String name;
    private int age;
    //有参无参构造
    public Student(){}
    public Student(String name,int age){
        setName(name);
        setAge(age);
    }
    //get,set方法
    public String getName() {
        return name;
    }
    public void setName(String name){
        this.name=name;
    }
    public int getAge(){
        return age;
    }
    public void setAge(int age){
        if(age>0&&age<100){
            this.age=age;
        }else{
            System.out.println("年龄不合理哦!");
        }
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return "{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
